package=@PACKAGE_NAME@
version=@PACKAGE_VERSION@
tarname=@PACKAGE_TARNAME@
distdir=$(tarname)-$(version)
stackversion=@STACK_NAME@.$(version)

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@

tmp_dir:=$(shell mktemp -d)

AMBARI_PATH?=@AMBARI_PATH@
AMBARI_STACK?=@AMBARI_STACK@

src=$(shell find src -type f \
	-not -name '.hash' \
	-not -name 'Makefile.in' \
	-not -name 'archive.zip' \
	-not -path '*/.*' \
	-not -path '*/services/MINECRAFT/*' \
)

dist: $(distdir).tar.gz

$(distdir).tar.gz: $(distdir)
	cd "$(tmp_dir)" ;\
		tar cof - $(distdir) |\
			gzip -9 -c > $(shell pwd)/$(distdir).tar.gz

$(distdir): $(src)
	mkdir -p $(tmp_dir)/$(distdir)
	cp --parents $? $(tmp_dir)/$(distdir)
	mv $(tmp_dir)/$(distdir)/src/* $(tmp_dir)/$(distdir) && rm -r $(tmp_dir)/$(distdir)/src

test:
	python -m unittest discover tests/

clean:
	find . -name '*.pyc' -delete
	rm -rf $(tmp_dir)
	find . -name "Makefile" -delete

Makefile: Makefile.in config.status
	./config.status Makefile

config.status: configure
	./config.status --recheck
